/** 移除对象的空属性 */
export function removeObjectEmpty(obj: Record<string, any>): Record<string, any> {
  Object.keys(obj).forEach((k) => {
    if (obj[k] === undefined) {
      delete obj[k];
    }
  });
  return obj;
}

/** 移除对象的空属性 */
export function str2Obj<T extends Record<string, unknown> | unknown[] | undefined>(obj: unknown): T {
  if (typeof obj === 'string') {
    try {
      return JSON.parse(obj);
    } catch (e) {
      return undefined as T;
    }
  } else {
    return undefined as T;
  }
}
